
import os 
import re

file_name='benchmark.mtx'
val_file='val.txt'
col_file='col.txt'
eor_file='eor.txt'
with open(file_name, 'r') as f:
	lines=f.readlines()

	rows=int(lines[0].split(' ')[0])
	graph=[]
	for i in range(rows):
		graph.append(list())

	for i in range(1,len(lines)):
		if re.match('%', lines[i]):
			pass
		else:
			row,col=lines[i].split(' ')
			graph[int(row)].append(col)

with open(val_file, 'w') as f:
	for row_list in graph:
		if len(row_list) != 0:
			for col_idx in row_list:
				f.write('1.0\n')
with open(col_file, 'w') as f:
	for row_list in graph:
		if len(row_list) != 0:
			for col_idx in row_list:
				f.write(col_idx)

with open(eor_file, 'w') as f:
	for row_list in graph:
		ele_num=len(row_list)
		for i in range(0, ele_num-1):
			f.write('0\n')
		if ele_num >= 1:
			f.write('1\n')